package com.moss.web;

import com.github.pagehelper.PageInfo;
import com.moss.common.core.BaseController;
import com.moss.common.domain.AjaxResult;

import com.moss.common.entity.SysPostEntity;
import com.moss.system.service.PostService;

import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 岗位管理
 */
@RestController
@RequestMapping("post")
public class PostController extends BaseController {

    @Resource
    PostService postService;


    @GetMapping("/list")
    public AjaxResult<List<SysPostEntity>> list(SysPostEntity post){
        startPage();
        List<SysPostEntity> list = postService.selectList(post);
        return AjaxResult.success(list,new PageInfo<>(list).getTotal());
    }

    @PostMapping("/savePost")
    public AjaxResult<Void> savePost(@RequestBody SysPostEntity post){
        post.setCreateBy(getUserId());
        postService.savePost(post);
        return AjaxResult.success();
    }

    @GetMapping("/{postId}")
    public AjaxResult<SysPostEntity> getPost(@PathVariable Long postId){
        return AjaxResult.success(postService.selectById(postId));
    }

    @PostMapping("/updatePost")
    public AjaxResult<Void> updatePost(@RequestBody SysPostEntity post){
        post.setUpdateBy(getUserId());
        postService.updatePost(post);
        return AjaxResult.success();
    }

    @PostMapping("/deletePost")
    public AjaxResult<Void> deletePost(Long[] postIds){
        postService.deletePost(postIds);
        return AjaxResult.success();
    }
}
